/*
 * Copyright (c) 2023 iQi.Co.Ltd. All rights reserved.
 */
 
using IQIGame.Onigao.Framework;
using System.Collections.Generic;
using System.Linq;
using System;
using NetProtocol.Enum;

namespace NetProtocol.POD {

	/// <summary>
	///  创建战斗
	/// module : structs_internal
	/// </summary>
	public class CreateBattlePOD : IPOD 
    {
        public readonly static Func<CreateBattlePOD> FACTORY = () => new CreateBattlePOD();
		public static Func<CreateBattlePOD> DynamicFactory = FACTORY;
        
		/*-- members --*/
		/// <summary>
        /// 
        /// </summary>
		public bool isLocal;
		/// <summary>
        ///  pve时HP等属性是否由战斗初始化，默认true	
        /// </summary>
		public bool initAttrbute;
		/// <summary>
        ///  战斗类型
        /// </summary>
		public BattleType battleType;
		/// <summary>
        /// 
        /// </summary>
		public long id;
		/// <summary>
        /// 
        /// </summary>
		public int randomSeed;
		/// <summary>
        ///  房主玩家
        /// </summary>
		public long hostPlayerId;
		/// <summary>
        ///  突袭队伍id
        /// </summary>
		public BattleTeamId strikeTeam;
		/// <summary>
        ///  红队，pve时固定为玩家
        /// </summary>
        private List<BattleTeamPOD> m_redTeams;
		/// <summary>
        ///  蓝队，pvs时固定为怪物
        /// </summary>
        private List<BattleTeamPOD> m_blueTeams;
		/// <summary>
        /// 
        /// </summary>
		public int battleScene;
		/// <summary>
        ///  关联的关卡id
        /// </summary>
		public int levelCid;
		/// <summary>
        ///  所有关联玩家
        /// </summary>
        private List<long> m_allPlayers;
		
		
        public List<BattleTeamPOD> redTeams
        {
            get
            {
                if(m_redTeams == null)
                {
                    m_redTeams = new();
                }
                return m_redTeams;
            }
            private set => m_redTeams = value;
        }
        public List<BattleTeamPOD> unsafe_redTeams
        {
        	get => m_redTeams;
        	set => m_redTeams = value;
        }
        public List<BattleTeamPOD> blueTeams
        {
            get
            {
                if(m_blueTeams == null)
                {
                    m_blueTeams = new();
                }
                return m_blueTeams;
            }
            private set => m_blueTeams = value;
        }
        public List<BattleTeamPOD> unsafe_blueTeams
        {
        	get => m_blueTeams;
        	set => m_blueTeams = value;
        }
        public List<long> allPlayers
        {
            get
            {
                if(m_allPlayers == null)
                {
                    m_allPlayers = new();
                }
                return m_allPlayers;
            }
            private set => m_allPlayers = value;
        }
        public List<long> unsafe_allPlayers
        {
        	get => m_allPlayers;
        	set => m_allPlayers = value;
        }
		
		/*-- constructors --*/
		public CreateBattlePOD() {}
		public CreateBattlePOD(bool isLocal, bool initAttrbute, BattleType battleType, long id, int randomSeed, long hostPlayerId, BattleTeamId strikeTeam, List<BattleTeamPOD> redTeams, List<BattleTeamPOD> blueTeams, int battleScene, int levelCid, List<long> allPlayers) {
			this.isLocal = isLocal;
			this.initAttrbute = initAttrbute;
			this.battleType = battleType;
			this.id = id;
			this.randomSeed = randomSeed;
			this.hostPlayerId = hostPlayerId;
			this.strikeTeam = strikeTeam;
			this.m_redTeams = redTeams;
			this.m_blueTeams = blueTeams;
			this.battleScene = battleScene;
			this.levelCid = levelCid;
			this.m_allPlayers = allPlayers;
		}
	      public void Serial(SOutputStream _out) {
            _out.Write_boolean(isLocal);
            _out.Write_boolean(initAttrbute);
            _out.Write_byte((sbyte)battleType);
            _out.Write_long(id);
            _out.Write_int(randomSeed);
            _out.Write_long(hostPlayerId);
            _out.Write_byte((sbyte)strikeTeam);
            _out.Write_list_pod(m_redTeams);
            _out.Write_list_pod(m_blueTeams);
            _out.Write_int(battleScene);
            _out.Write_int(levelCid);
            _out.Write_list_long(m_allPlayers); 
        }
        
        public void UnSerial(SInputStream _in) {
            if(!_in.HasRemaining()) return;
            isLocal = _in.Read_boolean();
            if(!_in.HasRemaining()) return;
            initAttrbute = _in.Read_boolean();
            if(!_in.HasRemaining()) return;
            battleType = (BattleType)_in.Read_byte();
            if(!_in.HasRemaining()) return;
            id = _in.Read_long();
            if(!_in.HasRemaining()) return;
            randomSeed = _in.Read_int();
            if(!_in.HasRemaining()) return;
            hostPlayerId = _in.Read_long();
            if(!_in.HasRemaining()) return;
            strikeTeam = (BattleTeamId)_in.Read_byte();
            if(!_in.HasRemaining()) return;
            m_redTeams = _in.Read_list_pod<BattleTeamPOD>(BattleTeamPOD.DynamicFactory);
            if(!_in.HasRemaining()) return;
            m_blueTeams = _in.Read_list_pod<BattleTeamPOD>(BattleTeamPOD.DynamicFactory);
            if(!_in.HasRemaining()) return;
            battleScene = _in.Read_int();
            if(!_in.HasRemaining()) return;
            levelCid = _in.Read_int();
            if(!_in.HasRemaining()) return;
            m_allPlayers = _in.Read_list_long();
        }
		
		public CreateBattlePOD Clone() {
            CreateBattlePOD o = DynamicFactory();
            o.isLocal = isLocal;
            o.initAttrbute = initAttrbute;
            o.battleType = battleType;
            o.id = id;
            o.randomSeed = randomSeed;
            o.hostPlayerId = hostPlayerId;
            o.strikeTeam = strikeTeam;
            if (m_redTeams != null) {
                o.m_redTeams = m_redTeams.ConvertAll(o => o?.Clone());
            }
            if (m_blueTeams != null) {
                o.m_blueTeams = m_blueTeams.ConvertAll(o => o?.Clone());
            }
            o.battleScene = battleScene;
            o.levelCid = levelCid;
            if (m_allPlayers != null) {
                o.m_allPlayers = new (m_allPlayers);
            }
            return o;
        }
        
        public void Clear() {
            isLocal = default;
            initAttrbute = default;
            battleType = default;
            id = default;
            randomSeed = default;
            hostPlayerId = default;
            strikeTeam = default;
            m_redTeams = default;
            m_blueTeams = default;
            battleScene = default;
            levelCid = default;
            m_allPlayers = default;
        }
		
        public override string ToString() {
			string str = "";
			str += "CreateBattlePOD [";
			str += "isLocal=";
			str += isLocal;
			str += ", initAttrbute=";
			str += initAttrbute;
			str += ", battleType=";
			str += battleType;
			str += ", id=";
			str += id;
			str += ", randomSeed=";
			str += randomSeed;
			str += ", hostPlayerId=";
			str += hostPlayerId;
			str += ", strikeTeam=";
			str += strikeTeam;
			str += ", redTeams=";
			str += m_redTeams.ToString<BattleTeamPOD>();
			str += ", blueTeams=";
			str += m_blueTeams.ToString<BattleTeamPOD>();
			str += ", battleScene=";
			str += battleScene;
			str += ", levelCid=";
			str += levelCid;
			str += ", allPlayers=";
			str += m_allPlayers.ToString<long>();
			str += "]";
			return str;
		}
		
	}
}